//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table 3 in the paper
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use August17ChanRoth.dta, clear

** drop player who participated mulitple times
drop if room=="HRSUs" | room=="FQkZh"

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

* Create Y variable
****** How many balls are used?
gen ballsused = 0
replace ballsused = 1 if player2action=="MixWithLowBlue"
replace ballsused = 1 if player2action=="MixWithHighBlue"
replace ballsused = 2 if player2action=="MixWithBothBlue"

****** Discard rate calculation
gen discardrate = 1-(ballsused/2)
replace discardrate =. if player1action!="Offer"

** Bad discard behavior
gen byte baddiscard = player1bluecount>player2lowbluecount & player1bluecount>player2highbluecount & player2action=="MixWithLowBlue" 
replace baddiscard =1 if player1bluecount>player2highbluecount & player1bluecount>player2lowbluecount & player2action=="MixWithHighBlue" 
replace baddiscard =1 if player1bluecount>player2lowbluecount & player1bluecount<player2highbluecount & player2action=="RejectOffer" 
replace baddiscard =1 if player1bluecount<player2lowbluecount & player1bluecount>player2highbluecount & player2action=="RejectOffer" 
replace baddiscard =2 if player1bluecount>player2lowbluecount & player1bluecount>player2highbluecount & player2action=="RejectOffer" 
replace baddiscard =. if player1action!="Offer" 

** Create bad discard rate
gen discard = 2-ballsused
gen baddiscard_rate = baddiscard/discard

* Make table

eststo clear

eststo: quietly reg player1bluecount status_quo if player1action=="Offer",  vce(cluster room) // Compare average recovered jar quality by treatment group

eststo: quietly reg discardrate status_quo,  vce(cluster room) // Compare kidney discard rate (jar acceptance rate) by treatment group
eststo: quietly reg discardrate status_quo player1bluecount,  vce(cluster room) // Compare kidney discard rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg discardrate status_quo player1bluecount player2highbluecount player2lowbluecount,  vce(cluster room) // Compare kidney discard rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg baddiscard_rate status_quo,  vce(cluster room) // Compare kidney BAD discard rate (jar acceptance rate) by treatment group
eststo: quietly reg baddiscard_rate status_quo player1bluecount,  vce(cluster room) // Compare kidney BAD discard rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg baddiscard_rate status_quo player1bluecount player2highbluecount player2lowbluecount,  vce(cluster room) // Compare kidney BAD discard rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

** Change the labels for table
label variable player1bluecount "Jar \# Blue Balls"
label variable player2highbluecount "High Urn \# Blue Balls"
label variable player2lowbluecount "Low Urn \# Blue Balls"

local numbers "& (1) & (2) & (3) & (4) & (5) & (6) & (7) \\ \hline"

esttab using table_discard_final.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01) b(3) mgroups("Jar \# Blue \textbar\ Recovered" "Jar Discard Rate \textbar\ Recovered" "\% of Bad Discards", pattern(1 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span) mlabels(none) nonumbers posthead( "`numbers'") label  title("Impact on Recovered Jar Quality, Discard Rates, and Discards that could have Benefited Urn(s)") substitute([htbp] [!htbp] \begin{tabular} \small\begin{tabular} {l} {p{\linewidth}}) addnotes("(Robust, clustered by player-pairings)") stat(N r2, label("N" "\[R^2\]") fmt(a3 %9.3fc))
